const { Service } = require('egg');
const path = require('path');
const fs = require('fs');
const Canvas = require('canvas');

class DrawImg extends Service {

    async drawFlawMap() {
        const canvas = createCanvas(200, 200)
        const ctx = canvas.getContext('2d')
        ctx.font = '30px Impact'

        ctx.rotate(0.1)
        ctx.fillText('Awesome!', 50, 100)

        // Draw line under text
        var text = ctx.measureText('Awesome!')
        ctx.strokeStyle = 'rgba(0,0,0,0.5)'
        ctx.beginPath()
        ctx.lineTo(50, 102)
        ctx.lineTo(50 + text.width, 102)
        ctx.stroke()

        const img = new Image()
        // Draw cat with lime helmet
        img.onload = () => ctx.drawImage(img, 0, 0)
        let res = canvas.toDataURL()
        return res;
    }
}

module.exports = DrawImg;